/**
 * 上海中赢金融信息服务有限公司
 * Copyright (c) 2017-2027 Chinazyjr,Inc.All Rights Reserved.
 */

package com.sys.midware.zookeeper.sample.node;

/**
 * 作业节点 <b>@author：</b> mobing <br/>
 * <b>@date：</b> 2016年5月31日 下午6:01:12 <br/>
 * <b>@version: </b> <br/>
 */
public final class SampleJobNode {

    /**
     * 根节点.
     */
    public static final String ROOT = "/job";

    public static final String JOB_ROOT = ROOT + "/%s";
    public static final String JOB_ID_APPENDIX = "jobId";
    public static final String JOB_ID = JOB_ROOT + "/jobId";
    public static final String JOB_NAME_APPENDIX = "jobName";

    public static final String JOB_NAME = JOB_ROOT + "/jobName";

    public static final String JOB_STATUS_APPENDIX = "status";
    public static final String JOB_STATUS = JOB_ROOT + "/status";

    public String getJobIdNode(final String jobName) {
        return String.format(JOB_ID, jobName);
    }
    
    public String getJobNameNode(final String jobName) {
        return String.format(JOB_NAME, jobName);
    }

    public String getJobStatusNode(final String jobName) {
        return String.format(JOB_STATUS, jobName);
    }


    /**
     * 判断是否是status的路径
     * @param  
     * @return  boolean
     */
    public boolean isStatusNode(final String path) {
        return path.startsWith(ROOT) && path.endsWith(SampleJobNode.JOB_STATUS_APPENDIX);
    }
    /**
     * 根据监控路径获取job的路径格式：/job/xxxx
     * 
     * @param
     * @return String
     */
    public String getJobPath(String path) {

        // path="/job/jingdongjob/jobName";
        String jobRoot = path.substring(0, path.lastIndexOf("/"));
        return jobRoot;
    }

    /**
     * 根据监控路径获取job的路径格式：/job/xxxx
     * 
     * @param
     * @return String
     */
    public String getJobIdPath(String path) {

        return getJobPath(path) + "/" + JOB_ID_APPENDIX;
    }

    /**
     * 根据监控路径获取job的路径格式：/job/xxxx
     * 
     * @param
     * @return String
     */
    public String getJobNamePath(String path) {

        return getJobPath(path) + "/" + JOB_NAME_APPENDIX;
    }

    public static void main(String[] args) {
        SampleJobNode jn = new SampleJobNode();
        String s = jn.getJobIdPath(null);
        System.out.println(s);
    }
    
}
